package other.nowcoder.easy;

import java.util.Scanner;

/**
 * @author Stark
 * @description 进制转换
 * @date 2022/4/21 15:38
 **/
public class ConversionOfNumber {
    public static void main(String[] args){
        //笨方法，下次不许写了
//        Scanner scanner = new Scanner(System.in);
//        while(scanner.hasNext()){
//            long M = scanner.nextLong();
//            int N = scanner.nextInt();
//            long num = N;
//            int n = 1;
//            if(M < 0){
//                M = -M;
//                System.out.print("-");
//            }
//            while(num <= M){
//                num *= N;
//                n++;
//            }
//            int tmp_n = n;
//            int[] arr = new int[n];
//            while(M != 0){
//                if(M - num >= 0){
//                    M -= num;
//                    arr[n] += 1;
//                }else{
//                    num = num / N;
//                    n--;
//                }
//            }
//            for(int i = tmp_n - 1;i >= 0;i--){
//                if(arr[i] <= 9)
//                    System.out.print(arr[i]);
//                else
//                    System.out.print((char)('A' + (arr[i] - 10)));
//            }
//            System.out.println();
//        }
        //正常写法
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            int M = scanner.nextInt();
            int N = scanner.nextInt();
            boolean flag = false;
            if(M == 0)
                System.out.println(0);
            else{
                if(M < 0) {
                    M = -M;
                    flag = true;
                }
                StringBuilder sb = new StringBuilder();
                String table = "0123456789ABCDEF";
                while(M != 0){
                    sb.append(table.charAt(M % N));
                    M /= N;
                }
                if(flag)
                    sb.append("-");
                sb.reverse();
                System.out.println(sb.toString());
            }
        }
    }
}
